import { defineStore } from 'pinia'
import router from '@/router'
import { LocalCache } from '../utils/LocalCache'
interface IUserInfo {
  email: string
  id: number
  mobile: string
  rid: number
  token: string
  username: string
}
export const LoginStore = defineStore('login', {
  state: () => {
    return {
      userInfo: {}
    }
  },
  actions: {
    changeUserInfo(info: IUserInfo) {
      this.userInfo = info
    },
    timeoutlogin() {
      this.userInfo = {}
      LocalCache.clearall()
      router.replace('/login')
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'login',
        storage: localStorage
      }
    ]
  }
})
